/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package at.alexanderpehm.ahnentafel.persistence;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 * Happenings during the life of a person, like birth, marriage, burial.
 * @author Alexander Pehm
 */
@Entity
public class Event implements Serializable {

    @ManyToMany(mappedBy = "events")
    private List<Person> persons;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToOne
    private Location location;
    @OneToMany
    private List<Note> notes;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date eventDate;
    private EventType eventType;
    @OneToMany
    private List<Media> media;
    @OneToMany
    private List<Source> sources;

    public List<Source> getSources() {
        return sources;
    }

    public void setSources(List<Source> sources) {
        this.sources = sources;
    }

    public List<Media> getMedia() {
        return media;
    }

    public void setMedia(List<Media> media) {
        this.media = media;
    }

    public List<Person> getPersons() {
        return persons;
    }

    public void setPersons(List<Person> persons) {
        this.persons = persons;
    }

    public Date getEventDate() {
        return eventDate;
    }

    public void setEventDate(Date eventDate) {
        this.eventDate = eventDate;
    }

    public EventType getEventType() {
        return eventType;
    }

    public void setEventType(EventType eventType) {
        this.eventType = eventType;
    }

    /**
     * The eventDate of the event.
     * @return event-eventDate
     */
    public Date getDate() {
        return eventDate;
    }

    /**
     * @see #getDate() 
     * @param eventDate event-eventDate
     */
    public void setDate(Date date) {
        this.eventDate = date;
    }

    public List<Note> getNotes() {
        return notes;
    }

    public void setNotes(List<Note> notes) {
        this.notes = notes;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    public enum EventType {

        Birth, Marriage, Divorce, Death, Burial, Other
    }

    @Override
    public String toString() {
        return "at.alexanderpehm.ahnentafel.persistence.Event[id=" + id + "]";
    }
}
